package com.cskaoyan.udp.edition3.oneperson;

import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

public class OnePerson {
    // 表示发送线程是否发出了886标志位
    public static boolean sendOffline = false;

    public static void main(String[] args) throws SocketException, UnknownHostException {

        // 创建用于发送和接收数据的DatagramSocket对象
        DatagramSocket datagramSocket = new DatagramSocket(9876);

        // 创建发送和接收数据的任务
        InetAddress targetIp = InetAddress.getByName("127.0.0.1");
        int port = 6789;
        SenderTask senderTask = new SenderTask(datagramSocket, targetIp, port);

        ReceiverTask receiverTask = new ReceiverTask(datagramSocket);

        // 让发送和接收任务，运行在两个线程中
        new Thread(senderTask, "发送线程").start();
        new Thread(receiverTask, "接收线程").start();


    }
}
